﻿using System;
using System.Web.UI;
using CurriculumData;

namespace CurriculumSite
{
    public partial class Vacancies : Page
    {
        #region Members

        private readonly Controller _controller = new Controller();
        
        #endregion

        #region Event Handlers

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CandidateId"] == null)
                Response.Redirect("~/Entry.aspx");
            DataBind();
        }

        protected void LinqDataSource_Selecting(object sender, System.Web.UI.WebControls.LinqDataSourceSelectEventArgs e)
        {
            e.Result = _controller.GetUnsubscribed(false, Convert.ToInt32(Session["CandidateId"]));
        }

        protected void subscribeASPxButton_Click(object sender, EventArgs e)
        {
            var vacanciesIds = vacanciesASPxGridView.GetSelectedFieldValues("VacancyId");           
            foreach (var vacancyId in vacanciesIds)
                _controller.Subscribe((int)vacancyId, (int)Session["CandidateId"]);
            Response.Redirect("~/Vacancies.aspx");
        }

        protected void subscribeWebUserControl_Subscribed(object sender, EventArgs e)
        {
            Response.Redirect(Request.Path);
        }        

        #endregion
    }
}
